


function search() {
    var param = {};
    param.woName = $("#PowerForm [name=woName]").val();//姓名
    param.woState = $("#PowerForm [name=woState]").val();//状态
    $("#powerTable").bootstrapTable("refresh",{query:param})
}

function optState(e) {
    return e==0?"启用":"禁用"
}
function optSex(e) {
    return e==0?"男":"女";
}

function authorize() {
    $("#authorizeForm").dialog("open")
    $(".modal-dialog").css("width","700px")
    $("#authorizeForm").css("display","block")
}

function initauthorizeForm() {
    $("#authorizeForm").dialog({
        title:"用户授权",
        btnVale:"授权",
        addBind:function () {
            var dep = $("#dep").val();//部门编号
            var woName = $("#woName").val();//用户编号
            var landPwd = $("#landPwd").val();//密码
            var landPwd2 = $("#landPwd2").val();//确认密码
            $("#zz input").change(function () {
                $(this).parent().siblings("p").children("span").html("");
            })
            $("#zz select").change(function () {
                $(this).parent().siblings("p").children("span").html("");
            })
            if(dep==-1){
                $("span.checkSe4").html("请选择部门!");
                return;
            }else if(woName==-1){
                $("span.checkSe5").html("请选择用户！");
                return;
            }else if(landPwd==null || landPwd==''){
                $("span.checkSe6").html("请输入用户密码!")
                return;
            }else if(landPwd.length<6){
                $("span.checkSe6").html("用户密码最低6位!")
                return;
            }else if(landPwd!=landPwd2){
                $("span.checkSe7").html("两次密码不一致!")
                return;
            }else{
                $.post(ctx+"/sys/updateUserPwd","woJubnum="+woName+"&landPwd="+landPwd,function (arr) {
                    toastr.info(arr);
                    $("#authorizeForm").dialog("close");
                    $("#powerTable").bootstrapTable("refresh")
                })
            }
        }
    })
};
function initDep() {
    $.post(ctx+"/sys/searchDep",null,function (arr) {
        $(arr).each(function () {
            var $opt = $("<option/>")
            $opt.val(this.deId)
            $opt.html(this.deName)
            $opt.appendTo("#dep")
        })
    },'json')
}
//部门改变的时候
function searchNotPwd(e) {
    $("#woName").children(":gt(0)").remove();
    var deId = $(e).val();
    if(deId!=-1){
        $(".woJu").remove()
        if(deId==2){
            $.post(ctx+"/sys/searchDivisionNotPwd",null,function (arr) {
                if(arr!=null && arr.length>0){
                    $(arr).each(function () {
                        var $opt = $("<option/>")
                        $opt.val(this.woJubnum)
                        $opt.html(this.woName)
                        $opt.appendTo("#woName")
                    })
                }else{
                    $(".woJu").remove()
                }
            },'json')
        }else{
            $.post(ctx+"/sys/searchNotPwd","deId="+deId,function (arr) {
                if(arr!=null && arr.length>0){
                    $(arr).each(function () {
                        var $opt = $("<option/>")
                        $opt.val(this.woJubnum)
                        $opt.html(this.woName)
                        $opt.appendTo("#woName")
                    })
                }else{
                    $(".woJu").remove()
                }
            },'json')
        }
    }else{
        $(".woJu").remove()
    }
}
function woNameChange(e) {
    var woJubnum = $(e).val();
    $(".woJu").remove()
    if(woJubnum!=-1){
        $.ajax({
            url:ctx+"/sys/searchWorkerDisplay",
            dataType:"json",
            data:"woJubnum="+woJubnum,
            type:"POST",
            async:false,
            success:function(msg){
                $("#woN").after($("<div class='form-group woJu'>"+
                    "<label class='col-md-2 control-label'>"+
                    "用户名:"+
                    "</label>"+
                    "<div class='form-group col-md-7'>"+
                    "<input type='text' value='"+msg.landCode+"' name='landCode' class='form-control' disabled='disabled' />"+
                    "</div>"+
                    "<p class=' col-md-3'' style='line-height: 34px; '>"+
                    "<i style='color: red;'>*</i>"+
                    "</p>"+
                    "</div>"));
            }
        });
        if($("#dep").val()==2&&$("#woName").val()!=-1){

            $.post(ctx+"/sys/searchByWoJubnum","woJubnum="+$("#woName").val(),function (arr) {
                $("#woN").after($("<div class='form-group woJu'>"+
                    "<label class='col-md-2 control-label'>"+
                    "负责科室:"+
                    "</label>"+
                    "<div class='form-group col-md-7'>"+
                    "<input type='text' value='"+arr.divName+"' name='divName' class='form-control' disabled='disabled' />"+
                    "</div>"+
                    "<p class=' col-md-3'' style='line-height: 34px; '>"+
                    "<i style='color: red;'>*</i>"+
                    "</p>"+
                    "</div>"));
            },'json')
        }
    }else{
        $(".woJu").remove()
    }
}
//初始化方法
$(function () {
    initDep()
    initauthorizeForm();//初始化模态框
    initEail();
})

function optEvent() {
    return '<a href="javascript:void(0)" class="eail"><i class="glyphicon glyphicon-envelope"></i></a>'
}
var use = null;
window.optEvents={
    "click .eail":function (e,value,row) {
        use=row;
        $("#woEmail").val(row.woEmail)
        $("#eailForm").dialog("open");
        $(".modal-dialog").css("width","70%");
        $(".modal-footer").css("display","none")
        $(".modal-body span.error").html("")
        $("#eailForm").css("display","block")
    }
}


function initEail() {
    $("#eailForm").dialog({
        title:"编辑邮件",
        btnValue:"发送",
        addBind:function () {

        }
    })
}
layui.use('layedit', function(){
    var layedit = layui.layedit
        ,$ = layui.jquery;

    //构建一个默认的编辑器
    var index = layedit.build('LAY_demo1');

    //编辑器外部操作
    var active = {
        content1: function(){

            var theme = $("#theme").val();//主题
            var text = layedit.getContent(index);//内容
            var Sendingmode = $("#eailForm [name=Sendingmode]:checked");
            var array = new Array();
            var Sendingmodes = $(Sendingmode).map(function () {
                return $(this).val();
            }).get().join("&");
            if(Sendingmode.length==0){
                $("span.checkSel").html("请选择发送方式!");
                return;
            }else if(theme==null || theme==''){
                $("span.checkSe2").html("请输入标题后再发送!");
                return;
            }else if(text==null || text==''){
                $("span.checkSe3").html("请输入内容后再发送!");
                return;
            }
            var woEmail = $("#woEmail").val();
            if($('#ema').is(':checked')) {
                swal({
                    title: '<h1 style="font-weight:bold;color:red">请输入邮箱密码!</h1>',
                    type: 'info',
                    html: '邮箱密码：<input type="password" id="pwd" name="pwd"/><span style="font-size: 12px" id="gg"></span>',
                    showCancelButton:true,
                    closeOnConfirm:false,
                    confirmButtonText:"确定",
                    confirmButtonColor:"#ec6c62"
                }).then(function(){
                    var pp = $("#pwd").val();
                    if(pp==null || pp==''){
                        toastr.warning("请输入密码!")
                        return;
                    }
                    var param = {};
                    param.pwd = $("#pwd").val();
                    param.theme=theme;
                    param.text=text;
                    param.Sendingmode=Sendingmodes;
                    param.woEmail = woEmail;
                    param.phone=use.woPhone;
                    param.woJubnum=use.woJubnum;
                    $.post(ctx+"/sys/SendMailbox",param,function (msg) {
                        toastr.info(msg);
                        $("#eailForm").dialog("close");
                    },'text')
                });
            }else{
                var param = {};
                param.pwd = $("#pwd").val();
                param.theme=theme;
                param.text=text;
                param.Sendingmode=Sendingmodes;
                param.woEmail = woEmail;
                param.phone=use.woPhone;
                param.woJubnum=use.woJubnum;
                $.post(ctx+"/sys/SendMailbox",param,function (msg) {
                    toastr.info(msg);
                    $("#eailForm").dialog("close");
                },'text')
            }

        }
    };

    $('.site-demo-layedit').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

});